/**
 * User: alesj
 * Date: 20.1.2006
 * Time: 18:05:58
 * 
 * (C) Genera Lynx d.o.o.
 */

package com.alesj.blueberry.sar.messages.impl;

import com.alesj.blueberry.sar.messages.MessageRepository;
import org.springframework.context.MessageSource;

import java.util.Locale;

/**
 * Holds basic logic for getting resource messages.
 * One should only implement init methods where the
 * message source is actually set.
 *
 * @author <a href="mailto:ales.justin@genera-lynx.com">Ales Justin</a>
 */
public abstract class AbstractMessageRepository implements MessageRepository {

    private MessageSource messageSource;

    protected abstract void init();

    public String getMessage(String key, Object[] args) {
        if (messageSource == null) {
            init();
        }
        return messageSource.getMessage(key, args, Locale.getDefault());
    }

    protected void setMessageSource(MessageSource messageSource) {
        this.messageSource = messageSource;
    }

}
